import React from 'react'
import { v4 as uuid } from 'uuid'
import PubSub from 'pubsub-js'
// 1111
/** */
export default class Weather extends React
  .Component {
  state = {
    arr: [1],
    x: 0
  }
  send = () => { 
    this.props.say('hello')
    // 发布消息
    PubSub.publish('gift', {gift: '月亮'})
  }
  handleChange = () => {
    let { arr } = this.state
    arr.map((item) => { 
      // // 对象式
      // this.setState({
      //   x: 1
      // }, () => { 
      //   console.log('24', this.state.x);
      // })
      // 函数式
      this.setState((state) => { 
        console.log('28', state);
        return {
          x: 1
        }
      })
      // 异步更新
      console.log('34', this.state.x);
    })
  }

  render() { 
    console.log('uuid', uuid());
    console.log(this);
    return (
      <div>
        <h4>Weather组件</h4>
        <div style={{ fontSize: '20px' }}>{ this.state.x }</div>
        <input
          type="checkbox"
          defaultChecked={true}
          onChange={ this.handleChange}
        />
        <button onClick={ this.send}>点击发布消息</button>
      </div>
    )
  }
 }
